package it.greg.findparty.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

public class GestoreDate {

	public String[] getDateRangeAsStrings(Date start, int length){
		String[] date_array;
		List<Date> date = getDateRange(start, length);
		date_array = new String[date.size()];
		Iterator<Date> it = date.iterator();
		for (int i=0;i<date.size();i++){
			date_array[i] = format(it.next());
		}
		return date_array;
	}
	
	public List<Date> getDateRange(Date start, int length) {
		List<Date> range = new ArrayList<Date>();
		range.add(start);
		if (length>0){
			Date d = start;
			while(length>0){
				d = addDay(d);
				range.add(d);
				length--;
			}
		}
		return range;
	}
	
	public String format(Date date){
		DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.ITALY);
		return dateFormat.format(date);
	}

	public Date addDay(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.DATE, 1);
		return cal.getTime();
	}
}
